package com.app.utils;

import com.app.model.InvitationCodeModel;
import org.springframework.beans.factory.annotation.Autowired;

import java.security.SecureRandom;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashSet;
import java.util.Set;

public class UniqueInviteCodeGenerator {

//    private static final String CHARACTERS = "0123456789";
    private static final int CODE_LENGTH = 8;

    private static SecureRandom random = new SecureRandom();

    public static String generateInviteCode() {
        StringBuilder sb = new StringBuilder();
//        for (int i = 0; i < CODE_LENGTH; i++) {
//            int randomIndex = random.nextInt(CHARACTERS.length());
//            char randomChar = CHARACTERS.charAt(randomIndex);
//            sb.append(randomChar);
//        }
//        LocalDate today = LocalDate.now();
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyddMM");
//        String dateString = today.format(formatter);

//        sb.append(dateString);

        return sb.toString();
    }

    public static String generateUniqueInviteCode() {
        Set<String> inviteCodes = new HashSet<>();
        String inviteCode;
        do {

            inviteCode = generateInviteCode();
        } while (!inviteCodes.add(inviteCode));
        return inviteCode;
    }

    public static void main(String[] args) {
        String uniqueInviteCode = generateUniqueInviteCode();
        System.out.println("Unique invite code: " + uniqueInviteCode);
    }
}